package com.javabasic.algorithm.leetcode;

/**
 * @author xiongmin
 * @version 0.0.1
 * @description Created by work on 2021/10/7 8:37 上午
 * @see
 */
public class NumberOfSegmentsInAString {
    /**
     * 暴力简单解法，通过Java中String提供的正则表达式切割的API计算结果
     * @param s
     * @return
     */
    public int countSegments(String s) {
        if (s != null || s.isEmpty() || s.trim().isEmpty()) {
            return 0;
        }
        String[] split = s.trim().split("\\s+");
        return split.length;
    }
}
